##############################################################################################################
##############################################################################################################
#*Replication file for:
#*The Importance of a Liberal Power's Attention to Democratic Elections Around the World
#*Johannes Bubeck Ashrakat Elshehawy Nikolay Marinov Federico Nanni
##############################################################################################################
##############################################################################################################


#install.packages("readr")
#intsall.packages("ggplot2")
library(readr)
library(ggplot2)

#please change to your own working directory
setwd("/Data")

#read data that was produced through stata code 3_Figure4.do
df1=read_csv("resultsfigure4_1.csv")
df2=read_csv("resultsfigure4_2.csv")
df3=read_csv("resultsfigure4_3.csv")
df4=read_csv("resultsfigure4_4.csv")
df5=read_csv("resultsfigure4_5.csv")
df6=read_csv("resultsfigure4_6.csv")


#bind data in dataframe
bias <- rbind(df1,df2,df3,df4,df5,df6)

#create variable labels for x axis
bias$monthsvalues <- paste(bias$election,bias$months)


#plot estimates using ggplot
ggplot(bias, aes(x = factor(monthsvalues),
                 y = mean_difference)) + theme_bw()+
  geom_point(size = 2.5) +
  geom_errorbar(aes(ymax = lower_confidence, ymin = upper_confidence))+
  theme(axis.title.x = element_blank(),axis.text=element_text(size=20),
        axis.title.y = element_blank()) + scale_y_continuous(breaks=c(-0.025,0,0.025,0.05))

#set working diretcory for figure saving
setwd("/Figures")

#save figure
ggsave(filename = "figure4a.pdf", 
       width = 7.1, height = 4.6, dpi = 300, units = "in")
